<template>
	<div class="page-wrap">
		<div class="page-content p-0">
			<div class="page-column p-0">
				<div class="page-form p-x-0">
					<el-form
						:model="ruleForm"
						:rules="rules"
						label-position="left"
						label-width="154px"
						ref="form"
						label-suffix="："
					>
						<el-row>
							<el-col :span="24">
								<el-form-item label="撤离人均花费" prop="CHEVACST001">
									<el-input
										size="medium"
										class="mediumForm"
										oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,10})?).*$/g, '$1')"
										v-model="ruleForm.CHEVACST001"
									>
										<template slot="append">元/人天</template>
									</el-input>
								</el-form-item>
								<el-form-item label="避迁人均花费" prop="CHRELCST001">
									<el-input
										size="medium"
										class="mediumForm"
										oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,10})?).*$/g, '$1')"
										v-model="ruleForm.CHRELCST001"
									>
										<template slot="append">元/人天</template>
									</el-input>
								</el-form-item>
								<el-form-item label="中期阶段持续时间" prop="DUR_INTPHAS">
									<el-input
										size="medium"
										class="mediumForm"
										oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,10})?).*$/g, '$1')"
										v-model="ruleForm.DUR_INTPHAS"
									>
										<template slot="append">s</template>
									</el-input>
								</el-form-item>
								<el-form-item label="长期阶段持续时间" prop="CHTMPACT001">
									<el-input
										size="medium"
										class="mediumForm"
										oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,10})?).*$/g, '$1')"
										v-model="ruleForm.CHTMPACT001"
									>
										<template slot="append">s</template>
									</el-input>
								</el-form-item>
								<el-form-item label="中期阶段剂量阈值" prop="CHDSCRTI001">
									<el-input
										size="medium"
										class="mediumForm"
										oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,10})?).*$/g, '$1')"
										v-model="ruleForm.CHDSCRTI001"
									>
										<template slot="append">sv</template>
									</el-input>
								</el-form-item>
								<el-form-item label="长期阶段剂量阈值" prop="CHDSCRLT001">
									<el-input
										size="medium"
										class="mediumForm"
										oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,10})?).*$/g, '$1')"
										v-model="ruleForm.CHDSCRLT001"
									>
										<template slot="append">sv</template>
									</el-input>
								</el-form-item>
								<el-form-item label="长期阶段关键器官" prop="CHCRTOCR001">
									<select-para
										style="width:100%"
										class="mediumForm"
										v-model="ruleForm.CHCRTOCR001"
										:label.sync="ruleForm.CHCRTOCR001Name"
										:options="CHCRTOCR001options"
									></select-para>
								</el-form-item>
								<el-form-item label="长期暴露持续时间" prop="CHEXPTIM001">
									<el-input
										size="medium"
										class="mediumForm"
										oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,10})?).*$/g, '$1')"
										v-model="ruleForm.CHEXPTIM001"
									>
										<template slot="append">s</template>
									</el-input>
								</el-form-item>
								<el-form-item label="禁制期间的资产贬值率" prop="CHDPRATE001">
									<el-input
										size="medium"
										class="mediumForm"
										oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,10})?).*$/g, '$1')"
										v-model="ruleForm.CHDPRATE001"
									>
										<template slot="append">每年</template>
									</el-input>
								</el-form-item>
								<el-form-item label="资产增值率" prop="CHDSRATE001">
									<el-input
										size="medium"
										class="mediumForm"
										oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,10})?).*$/g, '$1')"
										v-model="ruleForm.CHDSRATE001"
									>
										<template slot="append">每年</template>
									</el-input>
								</el-form-item>
								<el-form-item label="人均迁移成本" prop="CHPOPCST001">
									<el-input
										size="medium"
										class="mediumForm"
										oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,10})?).*$/g, '$1')"
										v-model="ruleForm.CHPOPCST001"
									>
										<template slot="append">元/人</template>
									</el-input>
								</el-form-item>
							</el-col>
						</el-row>
					</el-form>
				</div>
				<div class="bottom-btn">
					<el-button
						type="primary"
						:disabled="this.basic_Data.OCENDAT1001=='TRUE' ||this.early_Data.MIENDAT2001=='TRUE'"
						:loading="loading"
						@click="submitFun"
					>下一步</el-button>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
import selectPara from "@/components/selectPara"
import commCheckbox from "@/components/commCheckbox"
import ImageCropper from "@/components/ImageCropper"
import FixBottomButton from "@/components/FixBottomButton"
import ueditor from "@/components/ueditor"
import textLength from "@/components/common/comp/textLength"
import { commPara } from "@/mixins/mixins"
import { mapState } from "vuex"
import Axios from "axios"
import { dome, selecttext } from "@/utils/verify.js" 
export default {
	name: "aboutUs",
	props: {
		basicDataF: Object,
	},
	mixins: [commPara],
	components: {
		selectPara,
		ImageCropper,
		textLength,
		commCheckbox,
		FixBottomButton,
		ueditor,
	},

	data() {
		var CHEVACST001 = (rule, value, callback) => {
			if (value == "") {
				callback(new Error("输入值不能为空"))
			} else if (value < 0.0 || value > 1000.0) {
				callback(new Error("输入范围为[0.0，1000.0]"))
			} else {
				callback()
			}
		}
		var CHRELCST001 = (rule, value, callback) => {
			if (value == "") {
				callback(new Error("输入值不能为空"))
			} else if (value < 0.0 || value > 1000.1) {
				callback(new Error("输入范围为[0.0，1000.1]"))
			} else {
				callback()
			}
		}

		var DUR_INTPHAS = (rule, value, callback) => {
			if (value == "") {
				callback(new Error("输入值不能为空"))
			} else if (value < 0.0 || value > 3.1536e7) {
				callback(new Error("输入范围为[0.0，3.1536e7]"))
			} else {
				callback()
			}
		}
		var CHTMPACT001 = (rule, value, callback) => {
			if (value == "") {
				callback(new Error("输入值不能为空"))
			} else if (value < 0.0 || value > 1.0e10) {
				callback(new Error("输入范围为[0.0，1.0e10]"))
			} else {
				callback()
			}
		}
		var CHDSCRTI001 = (rule, value, callback) => {
			if (value == "") {
				callback(new Error("输入值不能为空"))
			} else if (value < 0.0 || value > 100000) {
				callback(new Error("输入范围为[0.0，100000]"))
			} else {
				callback()
			}
		}
		var CHDSCRLT001 = (rule, value, callback) => {
			if (value == "") {
				callback(new Error("输入值不能为空"))
			} else if (value < 1.0e-20 || value > 1.0e5) {
				callback(new Error("输入范围为[1.0E-20,1.0E+5]"))
			} else {
				callback()
			}
		}
		var CHDPRATE001 = (rule, value, callback) => {
			if (value == "") {
				callback(new Error("输入值不能为空"))
			} else if (value < 0.0 || value > 1.0) {
				callback(new Error("输入范围为[0.0，1.0]"))
			} else {
				callback()
			}
		}
		var CHPOPCST001 = (rule, value, callback) => {
			if (value == "") {
				callback(new Error("输入值不能为空"))
			} else if (value < 1.0e-6 || value > 1.0e6) {
				callback(new Error("输入范围为[ 1.0E-6，1.0E+6]"))
			} else {
				callback()
			}
		}

		return {
			activeTab: "2",
			allNuclide: [
				{
					ISOTPGRP_NAM: "2016-05-03",
					ISOTPGRP_GRP: "王小虎",
					RDCORINV_COR: 0,
				},
			],
			groupNuclide: [
				{
					ISMAXGRP001: "待定",
					ISDEPFLA_DRY: "TRUE",
					ISDEPFLA_WET: "TRUE",
				},
			],
			multipleSelection: [],
			CHCRTOCR001options: [],
			dialogVisible: false,
			ruleForm: {
				CHEVACST001: "27.0",
				CHRELCST001: "27.0",
				DUR_INTPHAS: "0.0",
				CHTMPACT001: 1.58e8,
				CHDSCRTI001: "100000",
				CHDSCRLT001: "0.04",
				CHCRTOCR001: "",
				CHCRTOCR001Name: "",
				CHEXPTIM001: "10000000000",
				CHDPRATE001: "0.20",
				CHDSRATE001: "0.12",
				CHPOPCST001: "5000.0",
			},
			rules: {
				CHEVACST001: [
					{
						validator: CHEVACST001,
						trigger: ["change", "blur"],
					},
				],
				CHRELCST001: [
					{
						validator: CHRELCST001,
						trigger: ["change", "blur"],
					},
				],
				DUR_INTPHAS: [
					{
						validator: DUR_INTPHAS,
						trigger: ["change", "blur"],
					},
				],
				CHTMPACT001: [
					{
						validator: CHTMPACT001,
						trigger: ["change", "blur"],
					},
				],
				CHDSCRTI001: [
					{
						validator: CHDSCRTI001,
						trigger: ["change", "blur"],
					},
				],
				CHDSCRLT001: [
					{
						validator: CHDSCRLT001,
						trigger: ["change", "blur"],
					},
				],
				CHCRTOCR001: [
					{
						validator: selecttext,
						trigger: ["change", "blur"],
					},
				],
				CHEXPTIM001: [
					{
						validator: CHTMPACT001,
						trigger: ["change", "blur"],
					},
				],
				CHDPRATE001: [
					{
						validator: CHDPRATE001,
						trigger: ["change", "blur"],
					},
				],
				CHDSRATE001: [
					{
						validator: CHDPRATE001,
						trigger: ["change", "blur"],
					},
				],
				CHPOPCST001: [
					{
						validator: CHPOPCST001,
						trigger: ["change", "blur"],
					},
				],
			},

			loading: false,
		}
	},
	computed: {
		...mapState({
			basic_Data: (state) => state.token.basic_Data,
			early_Data: (state) => state.token.early_Data,
			longterm_Data: (state) => state.token.longterm_Data,
		}),
	},
	mounted() {},
	methods: {
		setOption() {
			if (
				this.early_Data.DCF_FILE001 == "DOSDATA.INP" ||
				this.early_Data.DCF_FILE001 == "DOSDATA.NEW"
			) {
				this.getM(1)
			} else if (
				this.early_Data.DCF_FILE001 == "DOSD60.INP" ||
				this.early_Data.DCF_FILE001 == "DOSD825.INP"
			) {
				this.getM(2)
			}
		},
		getM(id) {
			let params = {
				dictypeid: id,
			}
			// console.log(params)
			this.loading = true
			this.$appApi
				.ZD_GET_DICINFOS(params)
				.then((res) => {
					if (res.data.substring(0, 1) == "S") {
						var str = res.data.substring(8) 
						this.MIORGDEF_ORG = JSON.parse(str) 
						this.CHCRTOCR001options = this.MIORGDEF_ORG.map(
							(item) => {
								return {
									label: item.dic_cname,
									value: item.dic_ename,
								}
							}
						)
						this.loading = false
					} else if (res.data.substring(0, 1) == "E") {
						let message = res.data.substring(6)
						this.$notify.error({
							title: "请求数据失败！",
							message: message,
							type: "success",
						})
					}
				})
				.catch((err) => {
					console.log(err)
				})
		},
		setData() {
			this.ruleForm.CHEVACST001 = this.longterm_Data.CHEVACST001
				? this.longterm_Data.CHEVACST001.toString()
				: "27.0"
			this.ruleForm.CHRELCST001 = this.longterm_Data.CHRELCST001
				? this.longterm_Data.CHRELCST001.toString()
				: "27.0"
			this.ruleForm.DUR_INTPHAS = this.longterm_Data.DUR_INTPHAS
				? this.longterm_Data.DUR_INTPHAS.toString()
				: "0.0"
			this.ruleForm.CHTMPACT001 = this.longterm_Data.CHTMPACT001
				? this.longterm_Data.CHTMPACT001.toString()
				: 1.58e8
			this.ruleForm.CHDSCRTI001 = this.longterm_Data.CHDSCRTI001
				? this.longterm_Data.CHDSCRTI001.toString()
				: 100000
			this.ruleForm.CHDSCRLT001 = this.longterm_Data.CHDSCRLT001
				? this.longterm_Data.CHDSCRLT001.toString()
				: "0.04"
			this.ruleForm.CHCRTOCR001 = this.longterm_Data.CHCRTOCR001
				? this.longterm_Data.CHCRTOCR001
				: ""
			this.ruleForm.CHEXPTIM001 = this.longterm_Data.CHEXPTIM001
				? this.longterm_Data.CHEXPTIM001.toString()
				: this.ruleForm.CHEXPTIM001
			this.ruleForm.CHDPRATE001 = this.longterm_Data.CHDPRATE001
				? this.longterm_Data.CHDPRATE001.toString()
				: "0.2"
			this.ruleForm.CHDSRATE001 = this.longterm_Data.CHDSRATE001
				? this.longterm_Data.CHDSRATE001.toString()
				: "0.12"
			this.ruleForm.CHPOPCST001 = this.longterm_Data.CHPOPCST001
				? this.longterm_Data.CHPOPCST001.toString()
				: "5000"
		},

		submitFun() {
			//保存
			this.$refs.form.validate((valid) => {
				if (valid) { 
					let tempdata = JSON.parse(
						JSON.stringify(this.longterm_Data)
					) 
					tempdata.CHEVACST001 = parseFloat(this.ruleForm.CHEVACST001)
					tempdata.CHRELCST001 = parseFloat(this.ruleForm.CHRELCST001)
					tempdata.DUR_INTPHAS = parseFloat(this.ruleForm.DUR_INTPHAS)
					tempdata.CHTMPACT001 = parseFloat(this.ruleForm.CHTMPACT001)
					tempdata.CHDSCRTI001 = parseFloat(this.ruleForm.CHDSCRTI001)
					tempdata.CHDSCRLT001 = parseFloat(this.ruleForm.CHDSCRLT001)
					tempdata.CHCRTOCR001 = this.ruleForm.CHCRTOCR001
					tempdata.CHEXPTIM001 = parseFloat(this.ruleForm.CHEXPTIM001)
					tempdata.CHDPRATE001 = parseFloat(this.ruleForm.CHDPRATE001)
					tempdata.CHDSRATE001 = parseFloat(this.ruleForm.CHDSRATE001)
					tempdata.CHPOPCST001 = parseFloat(this.ruleForm.CHPOPCST001)
					tempdata.SETPAGEINDEX = this.activeTab
					this.$store.dispatch("upData_longterm_Data", tempdata) 
					let params = {
						batchid: this.$route.query.id,
						batchinfo: "CHANGQI",
						submitjson: JSON.stringify(tempdata),
					} 
					this.$appApi
						.BATCH_SUBMIT(params)
						.then((res) => { 
							var str = res.data.substring(0, 1)
							if (str == "E") {
								let message = res.data.substring(6)
								this.$notify.error({
									title: "保存失败！",
									message: message,
									type: "success",
								})
							} else if (str == "S") {
								this.$notify({
									message: "保存成功！",
									type: "success",
								})
							}
						})
						.catch((err) => {
							console.log(err)
						})
					this.$emit("changeActiveTab", this.activeTab)
					this.$store.dispatch(
						"change_longterm_showTab",
						this.activeTab
					)
				}
			})
		},
	},
}
</script>
<style lang="scss" scoped>
.page-flex-row /deep/ .el-collapse-item__header {
	background: #f3f9fe;
}
</style>